<template>
    <div>
        <el-card shadow="always" class="mianbao">
            用户管理
        </el-card>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="birthday"
                    label="生日"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="姓名"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="username"
                    label="用户名"
                    width="100">
            </el-table-column>
            <el-table-column
                    prop="id"
                    label="手机号码"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="live"
                    label="地址">
            </el-table-column>
            <el-table-column
                    prop="email"
                    label="邮箱">
            </el-table-column>
            <el-table-column
                    prop="password"
                    label="密码">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">修改</el-button>
                    <el-button type="text" size="small" @click="xiangqing1(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="num"
                :page-size="10"
                layout="total, prev, pager, next"
                :total="total">
        </el-pagination>


        <el-dialog title="修改信息" :visible.sync="dialogFormVisible">
            <el-form :model="form">
                <el-form-item label="修改姓名" :label-width="formLabelWidth">
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="修改手机号码" :label-width="formLabelWidth">
                    <el-input v-model="form.id" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="修改地址" :label-width="formLabelWidth">
                    <el-input v-model="form.live" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="修改邮箱" :label-width="formLabelWidth">
                    <el-input v-model="form.email" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="修改用户名" :label-width="formLabelWidth">
                    <el-input v-model="form.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="修改密码" :label-width="formLabelWidth">
                    <el-input v-model="form.password" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="updateQian">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "qiantaiUser",
        data(){
            return{
                dialogFormVisible:false,
                tableData: [],
                num:1,
                total:0,
                form: {
                    name: null,
                    id:null,
                    live:null,
                    email:null,
                    password:null,
                    username:null,
                    oid:null
                },
                formLabelWidth: '120px'
            }
        },
        mounted(){
          this.init();
        },
        methods:{
            updateQian(){
                this.$http({
                    url:'/qiantaiuser/updateAll',
                    method:'put',
                    params: this.form
                }).then(result=>{
                    if(result.data>0){
                        this.$message({
                            type:'success',
                            message:'修改成功!'
                        });
                        this.dialogFormVisible=false;
                        this.form.name= null,
                            this.form.id=null,
                            this.form.live=null,
                            this.form.email=null,
                            this.form.password=null,
                            this.form.username=null,
                            this.form.oid=null
                        this.init();
                    }
                })
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.num=val;
                this.init();
            },
            init(){
                this.$http({
                    url:'/qiantaiuser/getAll',
                    method:'get',
                    params:{
                        num:this.num,
                        size:10
                    }
                }).then(result=>{
                    console.log(result);
                    if(result.status==200){
                        if(result.data.list){
                            this.tableData=result.data.list;
                            this.total=result.data.total
                        }
                    }
                })
            },
            xiangqing1(row){
                console.log(row);
                this.$http({
                    url:'/qiantaiuser/delete',
                    method:'delete',
                    params:{
                        oid:row.id
                    }
                }).then(result=>{
                    if(result.data>0){
                        this.$message({
                            type:'success',
                            message:'删除成功!'
                        })
                        this.init();
                    }else {
                        this.$message({
                            type:'error',
                            message:'删除失败'
                        })
                    }
                })
                this.miaoshu=row.sec;
                this.dialogVisible=true
            },
            handleClick(row) {
                this.dialogFormVisible=true;
                this.form.oid=row.id;
                console.log(row);
            }
        }
    }
</script>

<style scoped>
    .mianbao{
        text-align: center;
        margin-bottom: 20px;
    }
</style>
